import App from './App'
// main.js
import uviewPlus from '@/uni_modules/uview-plus'

// import chat from '@/utils/chat.js'
// uni.$chat = chat;


import http from '@/utils/http.js'
import {imagePath,baseUrl,imageUrl,nodataimg} from '@/utils/base.js';
import {uploadFile} from '@/utils/upload.js'
import pages from '@/utils/page.js'
for (let i in pages) {
	uni['$' + i] = pages[i]
}

import price from '@/components/price.vue'




function dimg(link){
	if(!link) return '';
	if(link.includes('http')){
		return link;
	}else{
		return imageUrl + link;
	}
};

function to(url,auth=true){
	console.log(url,auth)
	let flag = uni.getStorageSync('user');
	// let flag = true;
	if(auth && !flag) {
		uni.navigateTo({
			url:'/pages/Login/Login'
		})
		return;
	}
	uni.navigateTo({
		url
	})
};
// 间接跳转 翻转屏幕使用 由中间页面承载页面旋转 然后进行跳转
function tomid(url,direction){
	console.log('url',url)
	// url 要跳转的页面链接
	// type 1 进入下一页 2 返回上一页
	// direction landscape-primary 横屏 portrait-primary 竖屏
	uni.redirectTo({
		url:'/pages/MidPage?url='+encodeURIComponent(url)+'&direction='+direction
	})
};

function tt(title = '', icon = 'none'){
	uni.showToast({
		title,
		icon
	})
};

uni.$dimg = dimg
uni.$tt = tt
uni.$get = http.get
uni.$post = http.post
uni.$put = http.put
uni.$delete = http.delete
uni.$up = uploadFile
uni.$path = imagePath;		// 主包图片路径
uni.$img = imageUrl;
uni.$to = to;
uni.$tomid = tomid;
let num = 15;
// #ifdef MP-WEIXIN
num = (uni.getMenuButtonBoundingClientRect()?.width + 12) || 15
// #endif
import { createSSRApp } from 'vue';
import * as Pinia from 'pinia';
export function createApp() {
  const app = createSSRApp(App)
  app.component('price', price);
  app.config.globalProperties.$path = imagePath; // 主包图片路径
  app.config.globalProperties.$img = imageUrl;
  app.config.globalProperties.$icon = nodataimg;
  app.config.globalProperties.$pl = num+'px';
  app.config.globalProperties.$dimg = dimg;
  app.config.globalProperties.$to = to;
  app.config.globalProperties.$tomid = tomid;
  app.config.globalProperties.$tt = tt;
  app.use(uviewPlus)
  app.use(Pinia.createPinia())
  return {
    app,
	Pinia
  }
}
